package cn.edu.hizee.gps.dao;

import cn.edu.hizee.gps.model.Device;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

public interface DeviceRepository extends JpaRepository<Device,Integer>, CrudRepository<Device,Integer> {

//    <S extends Device> S save(Device device);

    Device findByDeviceNumber(String deviceNumber);


    /**
     * 查找设备对应用户信息
     * @return
     */
    @Query(nativeQuery = true, value = "SELECT " +
            "t_device.id, " +
            "t_device.device_number, " +
            "t_device.active_time, " +
            "t_device.last_open, " +
            "t_device.is_disable, " +
            "t_device.status, " +
            "t_device.is_bind, " +
            "t_user.real_name, " +
            "t_user.phone, " +
            "t_user.nickname " +
            "FROM " +
            "t_device " +
            "JOIN t_user_device on t_user_device.device_id = t_device.id " +
            "JOIN t_user on t_user_device.user_id = t_user.id")
    List<Map> findAllDevAndUser();
}
